package edu.gdkm.demo10.dasai;

import java.util.Random;

public class CunThread implements Runnable{
    private Integer money[];

    public CunThread(Integer money[]) {
        this.money = money;
    }

    @Override
    public void run() {
        while (true){
            synchronized(money) {
                this.apply();
            }
            try {
                Thread.sleep(new Random().nextInt(1000)+1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public synchronized void apply(){
        int applymoney = new Random().nextInt(500)+1 ; // 1-500之间的随机整数
        money[0] = money[0] +applymoney;
        System.out.println(Thread.currentThread().getName()
                +"获利￥"+applymoney+",当前余额："+money[0]);
    }

}
